package com.jiangmu_mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangmu_mall.mapper.AttrMapper;
import com.jiangmu_mall.pojo.Attr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Book;
import java.util.List;
import java.util.Map;

@Controller
public class AttrController {
    @Autowired
    AttrMapper attrMapper;
    @GetMapping("/")
    @ResponseBody
    public Object print(){
        List<Attr> attrs = attrMapper.selectList(null);
        return attrs;
    }

    @GetMapping("/page/{page}/{size}")
    @ResponseBody
    public Object selectBookPage1(@PathVariable("page") int num,@PathVariable("size") int size){
        Page<Attr> page = new Page<>(num, size);
        Page<Attr> page1 = attrMapper.selectPage(page, null);
        System.out.println("总页数"+page1.getPages());
        System.out.println("总数"+ page1.getTotal());
        return page;
    }

    @PostMapping("/insert")
    public int update(Attr attr){
        int insert = attrMapper.insert(attr);
        return insert;
    }


    @GetMapping("/index")
    public String index(){
        return "index";
    }
}
